package com.huawei.appgallery.appcomment.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import java.util.ArrayList;
import java.util.List;
import o.bcg.e;
import o.bcg.h;
import o.bed;

public class ReportTypeAdapter extends BaseAdapter {
    private boolean isChecked;
    private List<bed> list;
    private final Context mContext;
    private int[] reportTypeList = new int[]{h.ʻˊ, h.ʽᐝ, h.ʼᐝ, h.ʽˊ, h.ʾॱ, h.ʼˊ, h.ˊʼ, h.ʽˋ};

    static class a implements OnCheckedChangeListener {
        private bed ˋ;

        public a(bed o_bed) {
            this.ˋ = o_bed;
        }

        public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
            this.ˋ.ˏ(z);
        }
    }

    static class d {
        public RelativeLayout ˊ;
        public CheckBox ˎ;
        public TextView ˏ;

        private d() {
        }
    }

    public ReportTypeAdapter(Context context) {
        this.mContext = context;
        initList();
    }

    private void initList() {
        this.list = new ArrayList();
        for (int i = 0; i < 8; i++) {
            this.list.add(new bed());
        }
    }

    public int getCount() {
        if (this.reportTypeList == null || this.reportTypeList.length == 0) {
            return 0;
        }
        return this.reportTypeList.length;
    }

    public Object getItem(int i) {
        if (this.reportTypeList == null || this.reportTypeList.length == 0 || i >= this.reportTypeList.length) {
            return null;
        }
        return Integer.valueOf(this.reportTypeList[i]);
    }

    public long getItemId(int i) {
        return (long) i;
    }

    public View getView(int i, View view, ViewGroup viewGroup) {
        d dVar;
        int i2 = 0;
        if (view == null || !(view.getTag() instanceof d)) {
            dVar = new d();
            view = LayoutInflater.from(this.mContext).inflate(o.bcg.d.ʼ, null);
            dVar.ˊ = (RelativeLayout) view.findViewById(e.ᵎ);
            dVar.ˏ = (TextView) view.findViewById(e.ᐨॱ);
            dVar.ˎ = (CheckBox) view.findViewById(e.ᴵ);
            view.setTag(dVar);
        } else {
            dVar = (d) view.getTag();
        }
        bed o_bed = (bed) this.list.get(i);
        if (o_bed != null) {
            dVar.ˊ.setOnClickListener(new OnClickListener(this) {
                final /* synthetic */ ReportTypeAdapter ˊ;

                public void onClick(View view) {
                    this.ˊ.isChecked = dVar.ˎ.isChecked();
                    dVar.ˎ.setChecked(!this.ˊ.isChecked);
                }
            });
            Object item = getItem(i);
            TextView textView = dVar.ˏ;
            if (item != null) {
                i2 = getValueByString(String.valueOf(item), 0);
            }
            textView.setText(i2);
            dVar.ˎ.setOnCheckedChangeListener(new a(o_bed));
        }
        return view;
    }

    public static int getValueByString(String str, int i) {
        try {
            i = Integer.parseInt(str);
        } catch (NumberFormatException e) {
        }
        return i;
    }

    public String getCheckedReport() {
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < getCount(); i++) {
            if (((bed) this.list.get(i)).ॱ()) {
                stringBuilder.append(i + 1).append(HiAnalyticsConstant.REPORT_VAL_SEPARATOR);
            }
        }
        if (stringBuilder.length() > 0) {
            stringBuilder.deleteCharAt(stringBuilder.length() - 1);
        }
        return stringBuilder.toString();
    }
}
